<template>
  <div class="container">
    <!-- 总收益部分 -->
    <div class="box left-box" @click="toggleComponents">
      <div class="tatolBox">
        <div class="textContainer">
          <div>
            <span style="color: #5ca2f7">总收益（万元）</span>
          </div>
          <div>
            <span style="font-size: 40px; color: #fffeff">{{
              totalRevenue
            }}</span>
          </div>
        </div>
        <img src="../assets/moneyimage.png" class="imgMoney" />
      </div>
    </div>
    <div>
      <div class="textContainer">
        <div>
          <span style="color: #5ca2f7">昨日收益（元）</span>
        </div>
        <div>
          <span style="font-size: 40px; color: #fffeff">{{pastRevenue}}</span>
        </div>
      </div>
    </div>
    <!-- 渲染的组件 -->
    <div v-if="showComponents">
      <EarnMetrics style="margin-top: 10px"></EarnMetrics>
    </div>
  </div>
</template>

<script>
import EarnMetrics from "./EarnMetrics.vue";
export default {
  name: "EarningComponent",
  components: {
    EarnMetrics,
  },
  data() {
    return {
      showComponents: false, // 初始状态为隐藏
      totalRevenue: "", //总收益
      pastRevenue: "", //昨日收益
    };
  },
  created() {
    // 在组件创建时初始化 totalRevenue
    this.fetchTotalRevenue();
  },
  methods: {
    toggleComponents() {
      this.showComponents = !this.showComponents; // 切换状态
    },  
    //收益金额
    // async fetchTotalRevenue() {
    //   const res = await getData();
    //   if (res.data) {
    //     this.totalRevenue = res.data.data || {};
    //     this.pastRevenue = res.data.data || {};
    //   }
    // },

  },
};
</script>

<style scoped>
.container {
  display: flex;
  justify-content: space-between;
  gap: 30px;
  padding: 20px;
  width: 100%;
  box-sizing: border-box;
  border-radius: 8px;
}

.box {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex-grow: 1;
  background-color: #3578f2;
  border-radius: 8px;
}

.tatolBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
}

.textContainer {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.textContainer div {
  margin-bottom: 5px;
}

.title {
  font-size: 16px;
  color: #5ca2f7;
}

.value {
  font-size: 40px;
  color: #fffeff;
}

.imgMoney {
  width: 40px;
  height: 50px;
}
</style>
